/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mechanatrix.input;

import com.jme3.input.JoystickAxis;
import com.jme3.input.RawInputListener;
import com.jme3.input.event.JoyAxisEvent;
import com.jme3.input.event.JoyButtonEvent;
import com.jme3.input.event.KeyInputEvent;
import com.jme3.input.event.MouseButtonEvent;
import com.jme3.input.event.MouseMotionEvent;
import com.jme3.input.event.TouchEvent;

/**
 * Easier to watch for all button and axis events with a raw input listener.
 */
public class JoystickState implements RawInputListener {

	public volatile float xAxis;
	public volatile float yAxis;
	public volatile float zAxis;
	public volatile float zRotation;
	public volatile float povX;
	public volatile float povY;

	@Override
	public void beginInput() {
	}

	@Override
	public void endInput() {
	}

	@Override
	public void onJoyAxisEvent(JoyAxisEvent evt) {
		JoystickAxis axis = evt.getAxis();
		float value = evt.getValue();
		//String name = axis.getName();
		//System.out.println("Axis:" + name + "=" + value);
		if (axis == axis.getJoystick().getXAxis()) {
			xAxis = value;
		} else if (axis == axis.getJoystick().getYAxis()) {
			yAxis = -value;
		} else if (axis == axis.getJoystick().getAxis(JoystickAxis.Z_AXIS)) {
			zAxis = value;
		} else if (axis == axis.getJoystick().getAxis(JoystickAxis.Z_ROTATION)) {
			zRotation = -value;
		} else if (axis == axis.getJoystick().getPovXAxis()) {
			povX = value;
		} else if (axis == axis.getJoystick().getPovYAxis()) {
			povY = value;
		}
	}

	@Override
	public void onJoyButtonEvent(JoyButtonEvent evt) {
	}

	@Override
	public void onMouseMotionEvent(MouseMotionEvent evt) {
	}

	@Override
	public void onMouseButtonEvent(MouseButtonEvent evt) {
	}

	@Override
	public void onKeyEvent(KeyInputEvent evt) {
	}

	@Override
	public void onTouchEvent(TouchEvent evt) {
	}
}
